package com.thxrinfo.stop.controller;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.pig4cloud.pig.common.core.util.R;
import com.pig4cloud.pig.common.log.annotation.SysLog;
import com.thxrinfo.stop.api.entity.Region;
import com.thxrinfo.stop.service.RegionService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.security.SecurityRequirement;
import io.swagger.v3.oas.annotations.tags.Tag;
import lombok.RequiredArgsConstructor;
import org.springframework.http.HttpHeaders;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;


@RequestMapping({"/region"})
@RestController
@RequiredArgsConstructor
@Tag(name = "停车场区域管理")
@SecurityRequirement(name = HttpHeaders.AUTHORIZATION)
public class RegionController {

	private final RegionService regionService;

	@Operation(summary = "新增停车场区域", description = "新增停车场区域")
	@SysLog("新增停车场区域")
	@PostMapping
	@PreAuthorize("@pms.hasPermission('stop_region_add')" )
	public R save(@RequestBody Region region) {
		return R.ok(regionService.save(region));
	}

	/**
	 * 修改停车场区域
	 * @param region 停车场区域
	 * @return R
	 */
	@Operation(summary = "修改停车场区域", description = "修改停车场区域")
	@SysLog("修改停车场区域" )
	@PutMapping
	@PreAuthorize("@pms.hasPermission('stop_region_edit')" )
	public R updateById(@RequestBody Region region) {
		return R.ok(regionService.updateById(region));
	}

	/**
	 * 通过id删除停车场区域
	 * @param id id
	 * @return R
	 */
	@Operation(summary = "通过id删除停车场区域", description = "通过id删除停车场区域")
	@SysLog("通过id删除停车场区域" )
	@DeleteMapping("/{id}" )
	@PreAuthorize("@pms.hasPermission('stop_region_del')" )
	public R removeById(@PathVariable Long id) {
		return R.ok(regionService.removeById(id));
	}

	/**
	 * 通过id查询进出口管理
	 * @param id id
	 * @return R
	 */
	@Operation(summary = "通过id查询", description = "通过id查询")
	@GetMapping("/{id}" )
	@PreAuthorize("@pms.hasPermission('stop_region_get')" )
	public R getById(@PathVariable("id" ) Long id) {
		return R.ok(regionService.getById(id));
	}

	/**
	 * 分页查询
	 * @param page 分页对象
	 * @param region 停车场区域
	 * @return
	 */
	@Operation(summary = "分页查询", description = "分页查询")
	@GetMapping("/page" )
	@PreAuthorize("@pms.hasPermission('stop_region_get')" )
	public R<IPage<Region>> getParkingRegion(Page page, Region region) {
		return R.ok(regionService.page(page, region));
	}
}
